import {ref} from 'vue'
import {defineStore} from 'pinia'
import {cacheKeys} from '@/stores/constant/cacheKey'
import type {UserCache} from '@/model/user-import'

export const useUserCacheStore = defineStore(cacheKeys.USER_CACHE, () => {

			/**
			 * 用户名片缓存
			 */
			const userCache = ref<UserCache>({})

			/**
			 * 物品缓存
			 */
			const itemCache = ref<ItemCache>({})

			/**
			 * 建筑缓存
			 */
			const buildingCache = ref<BuildingCache>({})

			/**
			 * 生产建筑缓存
			 */
			const productionBuildingCache = ref<ProductionBuildingCache>({})

			const resetUserInfoStore = () => {
				userCache.value = {}
				itemCache.value = {}
				buildingCache.value = {}
				productionBuildingCache.value = {}
			}

			return {
				userCache: userCache,
				itemCache: itemCache,
				buildingCache: buildingCache,
				productionBuildingCache: productionBuildingCache,
				resetUserInfoStore: resetUserInfoStore
			}
		},
		{
			persist: {
				key: cacheKeys.USER_CACHE,
				storage: window.localStorage
			}
		}
)
